#lang racket

(define-struct inventory (name price))

(define (dis-list inv)
  (cond
    [(inventory? inv)
     (display (inventory-name inv ))
     (display " ")
     (display (inventory-price inv))
     (display "\n")]
  )
)

(define (show-inventory list)
  (cond 
    [(empty? list) (display "")]
    [else 
     (dis-list (first list))
     (show-inventory (rest list))])
  )

(define (extract price-level list)
  (cond 
    [(empty? list) empty]
    [else (cond
            [(< price-level (inventory-price (first list)))
             (cons (make-inventory 
                    (inventory-name (first list))
                    (inventory-price (first list))) 
                   (extract price-level (rest list)))]
            [else (extract price-level (rest list))])])
  )

(define (sum-inv inv-list)
  (cond
    [(empty? inv-list) 0]
    [else (+ (inventory-price (first inv-list))
             (sum-inv (rest inv-list)))])
  )

(define (add-tax inv-list)
  (cond
    [(empty? inv-list) empty]
    [else (cons (make-inventory
                 (inventory-name (first inv-list))
                 (* 1.087 (inventory-price (first inv-list))))
                (add-tax (rest inv-list)))])
  )

; Test
(define inventory-list
  (cons (make-inventory 'radish .56)
        (cons (make-inventory 'cabbage .73)
              (cons (make-inventory 'greens .64)
                    (cons (make-inventory 'carrot 1.2)
                          (cons ( make-inventory 'tomato 1.5)
                                (cons (make-inventory 'potato 1.3) empty)))))))

;(show-inventory inventory-list)
(show-inventory (extract .6 inventory-list))
(sum-inv inventory-list)
(show-inventory (add-tax inventory-list))
